package com.bookmarket.controller;

import com.bookmarket.entity.Admin;
import com.bookmarket.service.IAdminService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin")
public class WzAdminController {
    @Resource
    private IAdminService adminService;

    @RequestMapping("/adminLogin")
    public ModelAndView adminLogin(String name,String pass, HttpSession session, Model model){
              Admin admin=adminService.login(name,pass);
              if (admin!=null){
                  session.setAttribute("admin",admin);
                  return new ModelAndView("redirect:/admin/index.ftl");
              }else {
                  model.addAttribute("msg","登录失败");
                  return new ModelAndView();
              }
    }
}
